package com.xiyuan.smartutils.streams;

import java.io.IOException;
import java.io.OutputStream;

/**
 * 记录输入流长度的自定义输出流
 *
 * @version v1.0.0 @author lgz 2017-6-14 新建与整理
 */
public class LengthOutputStream extends OutputStream {
    private OutputStream out;
    private long length;
    
    public LengthOutputStream(OutputStream out) {
        this.out = out;
    }
    
    @Override
    public void write(int b) throws IOException {
        out.write(b);
        length++;
    }
    
    @Override
    public void write(byte[] b, int off, int len) throws IOException {
        out.write(b, off, len);
        length += len;
    }
    
    public long length() {
        return length;
    }
}
